import Vue from 'vue'
//引入路由库(路由插件)
import VueRouter from 'vue-router'

//安装插件
Vue.use(VueRouter)

//定义路由表
const routes = [
  /* 一个对象 表示 一个路由规则 */
  /* 一级路由: 详情页路由, 登录页路由, 搜索页路由  */
  {
    path: '/home',
    name: 'home',
    component: () => import( '../views/Home.vue'),
    children:[ //二级路由
      {
        path: '/home/index',
        name: 'index',
        component: () => import( '../views/Home/Index.vue'),
      },
      
      {
        path: '/home/my',
        name: 'my',
        component: () => import( '../views/Home/My.vue'),
      },
      {
        path: '/home',
        redirect:"/home/index" //二级路由重定向
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import( '../views/Login.vue')
  },
  {
    path: '/detail/:id', //详情页路由地址( 动态路由 )
    name: 'detail',
    component: () => import( '../views/Detail.vue')
  },
  {
    path: '/',
    redirect: "/home" //重定向
  }
]

//实例化路由对象
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
